///*
// * Project Name spring-boot-tools
// * File Name MinaSslFilter
// * Package Name com.huxiaosu.tools.mina.filter
// * Create Time 2024/5/25
// * Create by name：liujie
// */
//package com.huxiaosu.tools.mina.filter;
//
//import org.apache.mina.filter.ssl.KeyStoreFactory;
//import org.springframework.util.ResourceUtils;
//
//import javax.net.ssl.KeyManager;
//import javax.net.ssl.KeyManagerFactory;
//import javax.net.ssl.SSLContext;
//import java.io.File;
//import java.io.IOException;
//import java.security.GeneralSecurityException;
//import java.security.KeyManagementException;
//
///**
// * Description
// *
// * @author liujie
// * @date 2024/5/25 13:47
// */
//public class MinaSslFilter {
//    private static final String PROTOCOL = "TLS";
//    private static SSLContext serverInstance = null;
//
//    /**
//     * Get SSLContext singleton.
//     *
//     * @return SSLContext
//     * @throws java.security.GeneralSecurityException
//     *
//     */
//    public static SSLContext getInstance() throws GeneralSecurityException, IOException {
//        synchronized (MinaSslFilter.class) {
//            if (serverInstance == null) {
//                try {
//                    serverInstance = createBougusServerSslContext();
//                } catch (Exception ioe) {
//                    throw new GeneralSecurityException("Can't create Server SSLContext:" + ioe);
//                }
//            }
//        }
//
//        return serverInstance;
//    }
//
//    private static SSLContext createBougusServerSslContext() throws KeyManagementException, GeneralSecurityException, IOException {
//        SSLContext sslContext = SSLContext.getInstance(PROTOCOL);
//        sslContext.init(getKeyManagers(), BogusTrustManagerFactory.X509_MANAGERS, null);
//        return sslContext;
//    }
//
//    public static KeyManager[] getKeyManagers() throws GeneralSecurityException, IOException {
//        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KEY_MANAGER_FACTORY_ALGORITHM);
//        File keyStoreFile = ResourceUtils.getFile("classpath:keystore.jks");
//        final KeyStoreFactory keyStoreFactory = new KeyStoreFactory();
//        keyStoreFactory.setDataFile(keyStoreFile);
//        kmf.init(keyStoreFactory.newInstance(), KEYSTORE_PASSWORD.toCharArray());
//
//        return kmf.getKeyManagers();
//    }
//
//
//}
//
